﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace VISS.Web.BackEnd.Modules.User {

    public partial class PagingControl : System.Web.UI.UserControl {

        public long TotalRecord { get; set; }
        public int PageSize { get; set; }
        public string TargetPage { get; set; }
        public int CurrentPage { get; set; }
        public string QueryString { get; set; }

        protected int TotalPage { get; set; }
        protected string FirstLink { get; set; }
        protected string PreviousLink { get; set; }
        protected string NextLink { get; set; }
        protected string LastLink { get; set; }

        protected void Page_Load(object sender, EventArgs e) {

            if (TotalRecord > 0) {
                TotalPage = (int)(TotalRecord / PageSize);
                if (TotalRecord % PageSize != 0) {
                    TotalPage++;
                }

                if (CurrentPage == TotalPage) {
                    NextLink = string.Empty;
                    LastLink = string.Empty;
                }
                else {
                    NextLink = TargetPage + "?" + QueryString + "page=" + (CurrentPage + 1).ToString();
                    LastLink = TargetPage + "?" + QueryString + "page=" + TotalPage.ToString();
                }

                if (CurrentPage == 1) {
                    FirstLink = string.Empty;
                    PreviousLink = string.Empty;
                }
                else {
                    FirstLink = TargetPage + "?" + QueryString + "page=" + "1";
                    PreviousLink = TargetPage + "?" + QueryString + "page=" + (CurrentPage - 1).ToString();
                }
            }   
        }
    }
}

